package com.wyhello.tube4.spring.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wyhello.tube4.pojo.Bag;
import com.wyhello.tube4.pojo.Position;
import com.wyhello.tube4.pojo.Reside;
import com.wyhello.tube4.pojo.Tube;
import com.wyhello.tube4.spring.model.AnalysisDrawModel;
import com.wyhello.tube4.spring.model.BagRecordsModel;
import com.wyhello.tube4.spring.model.MeterRecordsModel;
import com.wyhello.tube4.spring.model.ResideRecordsModel;
/**
 * 受热面分析
 * @author Administrator
 *
 */
@Controller
public class AnalysisSurfaceDrawController {
	@Autowired
	private AnalysisDrawModel analysisDrawModel;
	@Autowired
	private MeterRecordsModel meterRecordsModel;
	@Autowired
	private ResideRecordsModel resideRecordsModel;
	@Autowired
	private BagRecordsModel bagRecordsModel;
	/**
	 * 查询锅炉信息
	 * @return
	 */
	@RequestMapping("/surfaceDraw/queryRealitys")
	public ModelAndView queryRealitys(){
		List<Reside> boilers =  meterRecordsModel.queryResideByBoiler();
		ModelAndView model = new ModelAndView("main");
		model.addObject("boilers",boilers);
		return model;
	}
	/**
	 * 查询指定锅炉下的受热面
	 * @param parentid
	 * @return
	 */
	@RequestMapping("/surfaceDraw/querySurface")
	public void querySurface(int parentid,HttpServletResponse response){
		Reside reside = resideRecordsModel.getResideById(parentid);
		Set<Reside> surfaceSet = reside.getResides();
		Map<Integer,String> map = new TreeMap<Integer,String>();
		for (Reside surface : surfaceSet) {
			map.put(surface.getId(), surface.getName());
		}
		JSONObject json = JSONObject.fromObject(map);
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.print(json);
	}
	
	/**
	 * 外径横向每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceDiameterX")
	public ModelAndView diameterX(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("outerDiameterX", begin, end, surfaceId);
		return model;
	}
	/**
	 * 外径纵向每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceDiameterY")
	public ModelAndView diameterY(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("outerDiameterY", begin, end, surfaceId);
		return model;
	}
	/**
	 * 蠕脹横向每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceCreepX")
	public ModelAndView creepX(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("creepValueX", begin, end, surfaceId);
		return model;
	}
	/**
	 * 蠕脹纵向每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceCreepY")
	public ModelAndView creepY(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("creepValueY", begin, end, surfaceId);
		return model;
	}
	/**
	 * 壁厚每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceWallThick")
	public ModelAndView wallThick(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("wallThick", begin, end, surfaceId);
		return model;
	}
	/**
	 * 蠕脹纵向每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceWearRate")
	public ModelAndView wearRate(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("wearRate", begin, end, surfaceId);
		return model;
	}
	/**
	 * 估算寿命每次测量的最大值、最小值、平均值
	 * @param rowId 管排ID
	 * @return
	 */
	@RequestMapping("/surfaceDraw/surfaceLifetime")
	public ModelAndView lifetime(int surfaceId,String begin,String end){
		
		ModelAndView model =  analysisDrawModel.getAnyliseSurface("lifetime", begin, end, surfaceId);
		return model;
	}
}
